package com.tronsis.distribution.biz.impl;

import android.app.Activity;

import com.google.gson.reflect.TypeToken;
import com.tronsis.distribution.bean.PayeeMethodBean;
import com.tronsis.distribution.bean.ReportBean;
import com.tronsis.distribution.bean.RulesMapBean;
import com.tronsis.distribution.bean.UserBean;
import com.tronsis.distribution.biz.CommonBiz;
import com.tronsis.distribution.http.Url;
import com.tronsis.library.http.HttpCallBack;
import com.tronsis.library.http.ListBean;
import com.tronsis.library.http.RequestClient;
import com.tronsis.library.http.RequestMethod;
import com.tronsis.library.http.UICallBack;

import java.util.List;


public class CommonBizImpl implements CommonBiz {

    @Override
    public void findUser(Activity activity, String phone, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, UserBean.class,false) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("phone",phone).excute(RequestMethod.GET, Url.FIND_USER);
    }

    @Override
    public void getCompanyPayeeList(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<List<PayeeMethodBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.COMPANY_PAYEE);
    }

    @Override
    public void getLeaderPayeeList(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<List<PayeeMethodBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.LEADER_PAYEE);
    }

    @Override
    public void pointConvert(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, Double.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.POINT_CONVER);
    }

    @Override
    public void getReportList(Activity activity, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<ReportBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.REPORT);
    }

    @Override
    public void submitReport(Activity activity, String detail, String reason, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("reason",reason,"detail",detail).excute(RequestMethod.POST, Url.REPORT);
    }

    @Override
    public void getRulesMap(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, RulesMapBean.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.RULES_MAP);
    }
}
